define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'cookie_records/index' + location.search,
                    add_url: 'cookie_records/add',
                    edit_url: 'cookie_records/edit',
                    del_url: 'cookie_records/del',
                    multi_url: 'cookie_records/multi',
                    import_url: 'cookie_records/import',
                    table: 'cookie_records',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false, //是否启用快速搜索
                columns: [
                    [
                        // {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        {field: 'created_at', title: __('使用时间')},

                        {field: 'analyze.device_memory', title: __('内存')},
                        {field: 'analyze.hardware_concurrency', title: __('频率')},
                        {field: 'analyze.unmasked_renderer', title: __('渲染器')},
                        {field: 'analyze.unmasked_vendor', title: __('供应商')},
                        {
                            field: 'analyze.use_state',
                            title: __('被使用状态'),
                            operate: false,
                            // cellStyle: Controller.api.formatter.css,
                            formatter:function (value,row) {
                                return '状态&nbsp;&nbsp;&nbsp;<i class="fa fa-question-circle-o" onmouseenter="roleupdate(this)" onmouseleave="roleupdate2(this)" data-id="'+row.analyze.id+'" ></i>';
                            }
                        },

                        {field: 'ana_id', title: __('Ana_id')},
                        {field: 'proxy_ip', title: __('Proxy_ip'), operate: 'LIKE'},
                        {field: 'proxy_from', title: __('Proxy_from'), operate: 'LIKE'},
                        {field: 'proxy_isp', title: __('Proxy_isp'), operate: 'LIKE'},
                        {field: 'is_use', title: __('Is_use'), operate: 'LIKE'},
                        {field: 'rounds', title: __('Rounds')},
                        {field: 'curr_location', title: __('Curr_location'), operate: 'LIKE'},
                        {field: 'last_location', title: __('Last_location'), operate: 'LIKE'},
                        {field: 'stage', title: __('类型'), operate: 'LIKE'},
                        {field: 'config_id', title: __('Config_id')},
                        {field: 'config_name', title: __('Config_name'), operate: 'LIKE'},
                        {field: 'config_type', title: __('Config_type'), operate: 'LIKE'},
                        {field: 'cookie', title: __('Cookie')
                        ,formatter:function (value,row) {
                                var url_str = '/tTrHFCUqIV.php/cookie_records/view_json?id='+row.id;
                                return '<a target="_blank" href="'+url_str+'">查看</a>';
                            }
                        },
                        // {field: 'updated_at', title: __('Updated_at')},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});


function roleupdate(e){
    $(e).addClass('fa-question-circle');
    $(e).removeClass('fa-question-circle-o');
    var id = $(e).attr('data-id');
    var fa_this = $(e);

    var str2 = '名称：状态</br>';
    $.post({
        async:true,
        url: "cookie_analyze/get_cookie_analyze_json",
        data:{'id':id},
        success: function(res3){
            $.each(res3.data, function (k2, v2) {
                str2 += k2+' ：'+v2+'</br>';
            });
            // console.log($(e));
            layer.tips(
                "<span style='color:black'>"+str2+"</span>",
                fa_this,
                {
                    area: ['300px', 'auto'],
                    // area: 'auto',
                    tips: [2, '#fff'],
                    time: 30000
                }
            );

        }
    });

}

function roleupdate2(e){
    $(e).addClass('fa-question-circle-o');
    $(e).removeClass('fa-question-circle');
    layer.closeAll();
}
